package com.prawn.web.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: zhy
 * @Date: 2019/7/11
 * @Description: 前台访问网关过滤器
 */
@Component
public class WebFileter extends ZuulFilter {

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("---前台网关过滤器---");
        RequestContext currentContext = RequestContext.getCurrentContext();
        HttpServletRequest request = currentContext.getRequest();
        //获取header，转发
        String header = request.getHeader("Authorization");
        if (header != null) {
            currentContext.addZuulRequestHeader("Authorization",header);
        }
        return null;
    }
}
